package cn.zlj.pethome.basic.controller;

import cn.zlj.pethome.basic.service.VerifyCodeService;
import cn.zlj.pethome.basic.dto.RegisterDto;
import cn.zlj.pethome.basic.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.io.IOException;

@RestController
@RequestMapping("/verifyCode")
public class VerifyCodeController {
    @Autowired
    private VerifyCodeService verifyCodeService;

    @GetMapping("/image/{key}")
    public AjaxResult verifyCode(@PathVariable("key") String key){
        String s = verifyCodeService.verifyCode(key);
        return AjaxResult.me().setResultObj(s);
    }
    @PostMapping("/smsCode")
    public AjaxResult smsCode(@RequestBody @Valid RegisterDto registerDto) throws IOException {
       verifyCodeService.smsCode(registerDto);
        return AjaxResult.me().success();
    }
}
